import 'dart:io';

import 'package:hx_base/pages/BaseToast.dart';
import 'package:permission_handler/permission_handler.dart';

class PermissionCheckUtils {
  // 文件权限
  static Future<bool> file(String reason) async {
    if (!Platform.isIOS) {
      BaseToast.showToast(reason, isAutoDismiss: false);
    }
    final status = await Permission.storage.request();
    if (!Platform.isIOS) {
      BaseToast.cancel();
    }
    if (status.isGranted) {
      return true;
    } else {
      BaseToast.showError("未获取文件访问权限，请在设置中获取文件访问权限");
      return false;
    }
  }

  ///相机权限
  static Future<bool> camera(String reason) async {
    if (!Platform.isIOS) {
      BaseToast.showToast(reason, isAutoDismiss: false);
    }
    final status = await Permission.camera.request();
    if (!Platform.isIOS) {
      BaseToast.cancel();
    }
    if (status.isGranted) {
      return true;
    } else {
      BaseToast.showToast("未获取相机权限,请在设置中获取相机权限");
      return false;
    }
  }

  ///相册权限
  static Future<bool> photos(String reason) async {
    if (!Platform.isIOS) {
      BaseToast.showToast(reason, isAutoDismiss: false);
    }
    final status = await Permission.photos.request();
    if (!Platform.isIOS) {
      BaseToast.cancel();
    }
    if (status.isGranted || status.isLimited) {
      return true;
    } else {
      BaseToast.showToast("未获取相册权限,请在设置中获取相册权限");
      return false;
    }
  }
}
